﻿/**
* 设计器面板。
*/
Ext.define('Happy.designer.Panel', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.happy-designer-panel',
    requires: [
        'Happy.designer.NodeDrager',
        'Happy.designer.NodeConnector',
        'Happy.designer.Rectangle',
        'Happy.designer.Ellipse'
    ],

    /**
     * 重写 ExtJs。
     * 
     * @protected
     */
    initComponent: function () {
        var me = this;

        me.drawer = Ext.widget({ xtype: 'draw' });

        Ext.apply(me, {
            autoScroll: true,
            layout: 'fit',
            items: me.drawer
        });

        me.callParent(arguments);
    },

    /**
     * 重写 ExtJs。
     * 
     * @protected
     */
    afterRender: function () {
        var me = this;

        me.callParent(arguments);

        me.dragger = Ext.create('Happy.designer.NodeDrager', this);

        me.connector = Ext.create('Happy.designer.NodeConnector', this);
    },

    /**
     * 添加节点。
     * 
     * @public
     * @param {Object} config 节点配置
     * @return {Happy.designer.Node} 节点实例
     */
    addNode: function (config) {
        var me = this;

        var node = Ext.create(config.type, me.drawer, config);

        me.dragger.allowDrag(node);

        me.connector.allowConnect(node);

        return node;
    },

    /**
     * 添加连线。
     * 
     * @public
     * @param {Object} config 连线配置
     * @return {Happy.designer.Node} 节点实例
     */
    addConnector: function (config) {
        var me = this;

    }
});